﻿using AnlianCommon.API.Commands.Fields;
using AnlianCommon.Common.DTO;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace AnlianCommon.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FieldController : ControllerBase
    {
        private readonly IMediator _mediator;
        public FieldController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 处理查看栏位命令
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result<List<FieldCottageDto>>> GetFieldCottage(FieldSearchCommand request, CancellationToken cancellationToken)
        {
            return await _mediator.Send(request, cancellationToken); 
        }

        /// <summary>
        /// 添加栏位
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> Handle(FieldCreateMoreCommand request, CancellationToken cancellationToken)
        {
            return await _mediator.Send(request, cancellationToken);
        }
    }
}
